﻿var YorkinPage = {};
YorkinPage.InitializePage = function (elems) {
   /* var submitActor = null;
    var LoginPattern = /Login/g;
    var CreatePattern = /Create/g;
    var $form = $('#form1');
    var $submitActors = $form.find('input[type=submit]');
    function validateEmail(email) {
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(email);
    }
    var ValidateLogin = function () {
        return true;
    };
    var ValidateCreate = function () {
        return true;
    };

    $form.submit(function (event) {
        if (null === submitActor) {
            submitActor = $submitActors[0];
        }
        if (LoginPattern.test(submitActor.name)) {
            return ValidateLogin();
        } else if (CreatePattern.test(submitActor.name)) {
            return ValidateCreate();
        }
    });

    $submitActors.click(function (event) {
        submitActor = this;
    });*/
    $("#" + elems.passwordRecoveryButton).click(function () {
        var email = $("#" + elems.forgotPasswordEmailInput).val();
        console.log(email);
        $.ajax({
            type: "POST",
            url: "Login.aspx/SendPasswordRecoveryEmail",
            data: JSON.stringify({ 'email': email }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                response = JSON.parse(response.d);
                console.log('here');
                $("#" + elems.forgotPasswordAjaxLoader).hide();
                if (response.STATUS == "SUCCESS") {
                    $("#" + elems.forgotPasswordStatusText).html("<b>GO</b>, go check your email :)");
                    $("#" + elems.forgotPassowrdStatusAlert).removeClass('alert-error').addClass('alert-success');
                    $("#" + elems.forgotPassowrdStatusAlert).show();
                } else {
                    $("#" + elems.forgotPasswordStatusText).html(response.MESSAGE);
                    $("#" + elems.forgotPassowrdStatusAlert).removeClass('alert-success').addClass('alert-error');
                    $("#" + elems.forgotPassowrdStatusAlert).show();
                }
            },
            error: function () {
                $("#" + elems.forgotPasswordAjaxLoader).hide();
                $("#" + elems.forgotPasswordStatusText).html("Uh-oh, the server's having some issues...");
                $("#" + elems.forgotPassowrdStatusAlert).removeClass('alert-success').addClass('alert-error');
                $("#" + elems.forgotPassowrdStatusAlert).show();
            }

        });
        $("#" + elems.forgotPasswordAjaxLoader).show();
        return false;
    });
};